
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include<QProcess>
#include<QDebug>
#include<QStringList>
#include<QString>
#include<QScreen>
#include<QDate>
#include<QGuiApplication>
#include<QPixmap>
#include<QStandardPaths>
#include<QFile>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

//    MainWindow::setWindowFlags(Qt::FramelessWindowHint);//隐藏边框

    //实现关机功能
    connect(ui->B1,&QToolButton::clicked,this,[=](){
        system("shutdown -s -t 0");
    });

    //实现截图功能
    connect(ui->B2,&QToolButton::clicked,this,[=](){
        showMinimized();

        QScreen *screen = QGuiApplication::primaryScreen();

        QString desktop_path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
        QString filePathName = desktop_path;

        qDebug()<<desktop_path;

        filePathName += "/full-";

        filePathName += QDateTime::currentDateTime().toString("yyyy-MM-dd hh-mm-ss-zzz");

        filePathName += ".jpg";

//        qDebug()<<filePathName;

        showMaximized();

        if(!screen->grabWindow(0).save(filePathName, "jpg"))

        {

//            qDebug()<<"save full screen failed";

        }
    });



    //实现快速打开屏幕讲述人功能
    connect(ui->B3,&QToolButton::clicked,this,[=](){
        QProcess * process = new QProcess;
        connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),[=]() //解决内存泄露问题
            {
            process->deleteLater();
            });
        process->start("cmd.exe", QStringList() << "/c" << "narrator");
    });

    //实现快速打开设备管理器功能
    connect(ui->B4,&QToolButton::clicked,this,[=](){
        QProcess * process = new QProcess;
        connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),[=]() //解决内存泄露问题
                {
                    process->deleteLater();
                });
        process->start("cmd.exe", QStringList() << "/c" << "Devmgmt.msc");
    });

    //实现快速打开任务管理器功能
    connect(ui->B5,&QToolButton::clicked,this,[=](){
        QProcess * process = new QProcess;
        connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),[=]() //解决内存泄露问题
                {
                    process->deleteLater();
                });
        process->start("cmd.exe", QStringList() << "/c" << "taskmgr");




    });



}

MainWindow::~MainWindow()
{
    delete ui;

}







void MainWindow::on_B6_clicked()
{
    Text * txtwindow = new Text;
    txtwindow->show();
}


void MainWindow::on_B7_clicked()
{
    cmd_ping_website * ping1 = new cmd_ping_website;
    ping1->show();
}

